<template>
  <el-dialog v-model="dialogVisible" title="修改密码" width="30%" :before-close="handleClose">
    <div class="user-dialog">
      <el-form inline ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="100px">
        <el-form-item style="width: 100%" label="新密码" prop="password" class="form-item-style">
          <el-input placeholder="输入新密码" style="width: 100%" v-model="ruleForm.password" type="password" />
        </el-form-item>

      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">关闭</el-button>
        <el-button type="primary" @click="submit"> 提交 </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { chgPswdApi } from "@/plugins/api/system/user";

let ruleForm = ref({});
let rules = {
  password: [{ required: true, message: "请输入新密码", trigger: "blur" }],

};
let dialogVisible = ref(false);
function handleClose(done) {
  // dialogVisible.value = false;
  ElMessageBox.confirm("是否确定关闭此对话框?")
    .then(() => {
      done();
    })
    .catch(() => {
      // catch error
    });
}
let title = ref("");
let ruleFormRef = ref(null);
function initFun(row) {
  if (ruleFormRef.value) {
    ruleFormRef.value.resetFields();
  }
  ruleForm.value = {};
  ruleForm.value.id = row.id
  dialogVisible.value = true;
}
const emit = defineEmits(["refreshList"]);
function submit() {
  if (!ruleFormRef.value) return;
  ruleFormRef.value.validate((valid, fields) => {
    if (valid) {
      let obj = Object.assign({}, ruleForm.value);

      chgPswdApi(obj).then((data) => {
        ElMessage.success("修改成功！");
        dialogVisible.value = false;
        emit("refreshList");
      });

    }
  });
}

onMounted(() => {

});
defineExpose({
  initFun,
});
</script>
<style scoped lang="scss">
.user-dialog {}
</style>
